package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.business.dao.inter.ElderLifeStyleDao;
import com.yunfeisoft.business.model.ElderLifeStyle;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import jdk.nashorn.internal.objects.annotations.Where;
import org.springframework.stereotype.Repository;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;

/**
 * ClassName: ElderLifeStyleDaoImpl
 * Description: 老人生活方式从表Dao实现
 * Author: Jackie liu
 * Date: 2020-04-04
 */
@Repository
public class ElderLifeStyleDaoImpl extends BaseDaoImpl<ElderLifeStyle, String> implements ElderLifeStyleDao {

    @Override
    public Page<ElderLifeStyle> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    /**
     * 根据healthId查询生活习惯
     * @param elderHealthId
     * @return
     */
    @Override
    public ElderLifeStyle getByHealthId(String elderHealthId) {
        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("elderHealthId", elderHealthId);
        List<ElderLifeStyle> lifeStyleList = query(wb);
        if (ObjectUtils.isEmpty(lifeStyleList)) {
            return null;
        }
        return lifeStyleList.get(0);
    }

    /**
     * 根据healthId删除
     * @param elderHealthId
     */
    @Override
    public void deleteByHealthId(String elderHealthId) {
        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("elderHealthId", elderHealthId);
        deleteByCondition(wb);
    }
}